package org.ksystem.practise.thread;

import org.ksystem.practise.thread.task.RunnableTask1;
import org.ksystem.practise.thread.task.ThreadTask1;
import org.ksystem.practise.thread.task.ThreadTask2;

public class MyThreadTest {

    public static void doMainPartTest() {
        for (int i = 600000; i < count; i++) {
            System.out.println(i);
        }
    }

    public static void doOriginalTest() {
        for (int i = 0; i < count; i++) {
            System.out.println(i);
        }
    }

    public static void doRunableTest() {
        RunnableTask1 task1 = new RunnableTask1(10);
        Thread thread1 = new Thread(task1, "Thread 1");
        Thread thread2 = new Thread(task1, "Thread 2");
        thread1.start();
        thread2.start();
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void doThreadTest() {
        ThreadTask1 task1 = new ThreadTask1();
        ThreadTask2 task2 = new ThreadTask2();
        task1.start();
        task2.start();
    }

    /**
     * main函数.
     * 
     * @param args
     *            启动参数
     * @throws Exception
     *             Exception
     */
    public static void main(String... args) throws Exception {

        Long timeBegin = System.currentTimeMillis();

        System.out.println("TIME BEGIN:" + timeBegin);

        // doOriginalTest();
        // doMainPartTest();
        doRunableTest();
        // doThreadTest();

        Long timeEnd = System.currentTimeMillis();

        System.out.println("END TIME:" + timeEnd + " TIME SPEND:" + (timeEnd - timeBegin) / 1000);

    }

    private static int count = 10;
}
